package com.firewolf.springsecurity.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.firewolf.springsecurity.entities.User;
import com.firewolf.springsecurity.entities.UserVo;
import lombok.Data;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 作者：刘兴
 * 时间:18/11/22
 **/
@RestController
@RequestMapping("user")
public class UserController {

    @RequestMapping("hello")
    public String hello() {
        return "hello,world";
    }


    @GetMapping
    @JsonView(User.UserInfo.class)
    public List<User> list(@RequestParam("xxx") String xxx, UserVo userVo,
                           @PageableDefault(size = 5,page = 1,sort = "name desc") Pageable page) {
        System.out.println(xxx);
        System.out.println(ReflectionToStringBuilder.toString(userVo));
        System.out.println(ReflectionToStringBuilder.toString(page));
        return Arrays.asList(
                new User(1, "liuxing", 30),
                new User(2, "zhangsan", 26),
                new User(3, "lisi", 25));
    }


    @GetMapping("{id}")
    @JsonView(User.UserDetail.class)
    public User getUserInfo(@PathVariable("id") Integer id){
        System.out.println(id);
        return new User(2,"liuxing",3);
    }

}
